#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    int n, h, k = 0;
    scanf("%d", &n);
    int ad[100] = { 0 };

    for (int i = 0; i < n; i++)
        ad[i] = i + 1;

    for (int i = 0; i < n - 1; i++)
    {
        int a = 0;
        for (;;)
        {
            k = k % n;
            if (ad[k] != 0)
                a++;
            k++;
            if (a % 3 == 0 && a != 0)
            {
                ad[k - 1] = 0;
                a = 0;
                break;
            }


        }



    }
    for (int i = 0; i < n; i++)
        if (ad[i] != 0)
            h = ad[i];
    printf("%d", h);
    return 0;

}